package me.landery.modules.sinco.repository;

import me.landery.modules.sinco.domain.Recharge;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

public interface RechargeRepository extends JpaRepository<Recharge, Long>, JpaSpecificationExecutor<Recharge> {
    /**
     * 根据 PID 查询
     * @param name pid
     * @return /
     */
    List<Recharge> findByBalance(Double name);

    /**
     * 根据用户ID查询
     * @param id 用户ID
     * @return /
     */
    @Query(value = "SELECT r.* FROM sys_recharge r WHERE " +
            "r.uid = ?1",nativeQuery = true)
    Set<Recharge> findByUserId(Long id);

    /**
     * 根据TradeNo查询
     * @param outTradeNo 商户订单号
     * @return
     */

    Recharge findByOutTradeNo(String outTradeNo);

    @Query(value = "SELECT SUM(balance) FROM `sinco_recharge`", nativeQuery = true)
    Double findAllBalance();

    List<Recharge> findByUserIdAndRechargeState(Long currentUserId, int i);
}